$(function() {
	loginsTo();
	$('.user-login').on('tap', function() {
		var reg = /(1[3-9]\d{9}$)/;
		if(!reg.test($('#name').val())) {
			mui.toast('请输入正确的手机格式');
			return false;
		};
		
		if(!$('#name').val()) {
			mui.toast('请输入您的名字');
			return false;
		};
		var mypwd = /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[])+$)([^(0-9a-zA-Z)]|[]|[a-zA-Z]|[0-9]){6,}$/;
		if(!mypwd.test($('#password').val())){
			mui.toast('请输入数字，符号，字母任意两种混合的密码');
			return false;
		};
		var rule = $('#rulelogin').is(':checked');
		if(!rule == true) {
			mui.toast('请先同意用户协议');
			return false;
		};

		var numberU = $('#name').val();
		var pass = $('#password').val();
		$.ajax({
			type: "post",
			cache: false,
			traditional: true,
			dataType: "json",
			url: window.address + "/user/login",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: {
				"phoneNo": numberU,
				"password": pass,
			},
			success: function(data) {
				console.log(data);
				var loginCode = data.code;
				if(data.data.vipIs==0){
					mui.toast('该账号暂未注册成功！');
					return false;
				};			
				if(data.code == 200) {
					var msgUserUuid = data.data.userUuid;
					setCookie('token', data.data.token, 100000, '/');
					getCookieValue("token");
					window.location.href = "u-home.html?business=" + msgUserUuid + "&login=" + getCookieValue("token");
				} else {
					mui.toast('账号或密码不正确');
				}
			}
		});
	});

});

var loginsTo = function(){
	$.ajax({
			type: "post",
			cache: false,
			traditional: true,
			dataType: "json",
			url: window.address + "/user/login",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: {
				"token":getCookieValue("token")
			},
			success: function(data) {
				console.log(data);
				var loginCode = data.code;
				if(data.data.vipIs==0){
					mui.toast('该账号暂未注册成功！');
					return false;
				};			
				if(data.code == 200) {
					var msgUserUuid = data.data.userUuid;
					window.location.href = "u-home.html?business=" + msgUserUuid + "&login=" + getCookieValue("token");
				} else {
					mui.toast('账号或密码不正确');
				}
			}
		});
}
